$(function(){
	/*********************************************广告后台开始****************************************************/
	/**
	 * 广告管理员信息列表
	 */
	$("#menu-adadmin-page").parent().click(function(){
		$.ajax({
			type:"POST",
			cache: false,
			url:ctx+"/ad_admin/list",
			data:"",
			success:function(msg){
				addPage(msg);
			},
			complete:function(){
				waitingStop();
			},
			beforeSend:function(){
				waiting();
			}
		});
	});
	/**
	 * 编辑广告信息列表
	 */
	$("#menu-ad-page").parent().click(function(){
		$.ajax({
			type:"POST",
			cache: false,
			url:ctx+"/ad/list",
			data:"",
			success:function(msg){
				addPage(msg);
			},
			complete:function(){
				waitingStop();
			},
			beforeSend:function(){
				waiting();
			}
		});
	});
	/**
	 * 审核广告信息列表
	 */
	$("#menu-adchecked-page").parent().click(function(){
		$.ajax({
			type:"POST",
			cache: false,
			url:ctx+"/ad/adcheckedlist",
			data:"",
			success:function(msg){
				addPage(msg);
			},
			complete:function(){
				waitingStop();
			},
			beforeSend:function(){
				waiting();
			}
		});
	});
	/**
	 * 广告小区信息列表
	 */
	$("#menu-adcommunity-page").parent().click(function(){
		$.ajax({
			type:"POST",
			cache: false,
			url:ctx+"/ad/adCommunityList",
			data:"",
			success:function(msg){
				addPage(msg);
			},
			complete:function(){
				waitingStop();
			},
			beforeSend:function(){
				waiting();
			}
		});
	});
	/**
	 * 广告信息列表
	 */
	$("#menu-passedad-page").parent().click(function(){
		$.ajax({
			type:"POST",
			cache: false,
			url:ctx+"/ad/passedList",
			data:"",
			success:function(msg){
				addPage(msg);
			},
			complete:function(){
				waitingStop();
			},
			beforeSend:function(){
				waiting();
			}
		});
	});
	/**
	 * 广告管理员操作日志信息列表
	 */
	$("#menu-adadminlog-page").parent().click(function(){
		$.ajax({
			type:"POST",
			cache: false,
			url:ctx+"/ad_adminlog",
			data:"",
			success:function(msg){
				addPage(msg);
			},
			complete:function(){
				waitingStop();
			},
			beforeSend:function(){
				waiting();
			}
		});
	});
	/**
	 * 广告系统反馈工单信息列表
	 */
	$("#menu-feedback-page").parent().click(function(){
		$.ajax({
			type:"POST",
			cache: false,
			url:ctx+"/ad/sys/feedback",
			data:"",
			success:function(msg){
				addPage(msg);
			},
			complete:function(){
				waitingStop();
			},
			beforeSend:function(){
				waiting();
			}
		});
	});
	
	
	/**
	 * 广告系统反馈工单历史工单
	 */
	$("#menu-feedbacklog2-page").parent().click(function(){
		$.ajax({
			type:"POST",
			cache: false,
			url:ctx+"/ad/sys/feedback/histroylist",
			/*data:{"state":2},*/
			success:function(msg){
				addPage(msg);
			},
			complete:function(){
				waitingStop();
			},
			beforeSend:function(){
				waiting();
			}
		});
	});
	
	/*********************************************广告后台结束****************************************************/
});

var tipsTimeoutTime;
var tipsTimeoutTimer; 
function tipsTimeout(){
	var temp = 
	'<div class="modal"  id="tipsTimeoutModal">'+
    '	<div class="modal-dialog  modal-sm" style="margin-top:15%">'+
    '   	<div class="modal-content model-linear">'+
	'			<div class="modal-body modal-oneline-body" style="padding: 8px;">'+	
	'			会话超时，<span id="tipsTimeoutTime" style="font-size:20px;color:#fff;"></span>秒将要重新登录'+	
	'			</div>'+
	'		</div>'+
	'	</div>'+
	'</div>';
	if($("#tipsTimeoutModal").length==0){
		$("div.viewFramework-body").append(temp);
	}
	var dialogWidth = $("#tipsTimeoutModal").find('.modal-dialog').width();
	$("#tipsTimeoutModal").find('.modal-dialog').css({
		'margin-left': function () { 
			return ($(window).width() - dialogWidth + $('div.viewFramework-sidebar').width())/2;
		}
	});
}

function tipsTimeoutTimerFunction(){
	tipsTimeoutTime--;
	if(tipsTimeoutTime <= 0){ 
		var ref = window.location.href;
		if(ref.indexOf('#')>0){
			ref = ref.replace('#','');
		}
		if(ref.indexOf('/') == ref.length-1){
			ref = ref.Substring(0,ref.length-1);
		}
		$("#tipsTimeoutModal").css("display","none");
		window.clearInterval(tipsTimeoutTimer);
		window.location.href = ref+'/';
	}else{
		$("#tipsTimeoutTime").text(tipsTimeoutTime);
	}
}

/**
 * 向工作区域添加面板
 */
function addPage(msg) {
	if(isOK(msg)){
		$("#work_area").empty();
		$("#work_area").append(msg);
		scrollPane();
		return true;
	}
	return false;
}

function isOK(msg){
	if(msg!=null && typeof msg == "string" && msg.indexOf('<form name="admin_login">')>0){
		if(tipsTimeoutTimer==null){
			tipsTimeoutTime = 5;
			tipsTimeout();
			$("#tipsTimeoutTime").text(tipsTimeoutTime);
			$("#tipsTimeoutModal").css("display","block");
			tipsTimeoutTimer = window.setInterval("tipsTimeoutTimerFunction()",1000);
		}
		return false;
	}
	return true;
}